<template>
  <div class="kaocha-details">
    <section class="wboxnoborder">
          <div v-show="pageloading">加载中...</div>
          <el-form ref="form"
            v-show="!pageloading"
            :model="kaochaForm"
            label-width="140px"
            label-position="right"
            :inline="true"
            style="margin:15px;">
            <el-form-item label="考察范围">
              <span class="selectioncontent">
                <span v-for="(item,index) in kaochaForm.examinationRange" :key="index"><span v-if="index>0">、</span>{{item}}</span>
              </span>
            </el-form-item>
            <el-form-item label="考察时间">
              <span class="selectioncontent">
                {{kaochaForm.date}}至
                {{kaochaForm.finishTime}}
              </span>
            </el-form-item>
            <div style="clear:both"></div>
            <el-form-item label="考察结果">
              <span class="selectioncontent">
                {{kaochaForm.num}}
              </span>
              人参加考察谈话。其中
              <span class="selectioncontent">
                {{kaochaForm.num2}}
              </span>
              人同意。
              <span class="selectioncontent">
                {{kaochaForm.num3}}
              </span>
              人不同意。
              <span class="selectioncontent">
                {{kaochaForm.num4}}
              </span>
              人弃权。
            </el-form-item>
            <el-table :data="ftsb" v-loading="loading" style="margin-bottom:15px" border >
              <el-table-column label="凡提四必情况">
                <el-table-column label="查核干部档案">
                  <template slot-scope="scope">
                    {{scope.row.ftsb1}}
                  </template>
                </el-table-column>
                <el-table-column label="查核有关事项">
                  <template slot-scope="scope">
                    {{scope.row.ftsb2}}
                  </template>
                </el-table-column>
                <el-table-column label="征求纪检监察部门意见">
                  <template slot-scope="scope">
                    {{scope.row.ftsb3}}
                  </template>
                </el-table-column>
                <el-table-column label="线索举报调查">
                  <template slot-scope="scope">
                    {{scope.row.ftsb4}}
                  </template>
                </el-table-column>
              </el-table-column>
            </el-table>
            <el-form-item label="是否和本人谈话">
              <span class="selectioncontent">
                是
              </span>
            </el-form-item>
            <div style="clear:both"></div>
            <el-form-item label="重要情况">
              <span class="selectioncontent">
                {{kaochaForm.zyqk}}
              </span>
            </el-form-item>
            <div style="clear:both"></div>
            <el-form-item label="任前报告情况">
              <span class="selectioncontent">
                {{kaochaForm.rqbg}}
              </span>
            </el-form-item>
            <div style="clear:both"></div>
            <el-form-item>
              <el-button type="primary" style="margin-left:140px" @click="exportdoc">生成考察素材模板</el-button>
                <el-button type="primary" @click="exportdoc2">导出档案查核表</el-button>
            </el-form-item>
            <div style="clear:both"></div>
            <el-form-item label="附件" prop="files">
              <div  v-for="(item, index) of kaochaForm.files" :key="index">
                <a :href="$http.defaults.baseURL+$http.defaults.selectionAPI+'api/gen/file/download?id='+item.id">{{item.fileName}}.{{item.fileType}}</a>
              </div>
            </el-form-item>
            <div style="clear:both"></div>
            <el-form-item label="考察组审核人">
              <span class="selectioncontent">
                {{kaochaForm.hcr}}
              </span>
            </el-form-item>
            <el-form-item label="审核时间">
              <span class="selectioncontent">
                {{kaochaForm.date2}}
              </span>
            </el-form-item>
            <div style="clear:both"></div>
            <el-form-item label="是否存在问题">
               <span class="selectioncontent" v-if="kaochaForm.problem == 1">是</span>
               <span class="selectioncontent" v-else>否</span>
            </el-form-item>
            <el-form-item label="存在问题" v-if="kaochaForm.problem == 1">
              <span class="selectioncontent">
                {{kaochaForm.hasproblem}}
              </span>
            </el-form-item>
            <div style="clear:both"></div>
            <el-form-item label="考察组成员">
              <span class="selectioncontent">
                {{kaochaForm.name}}
              </span>
            </el-form-item>
            <div style="clear:both"></div>
            <el-form-item label="备注">
              <span class="selectioncontent">
                {{kaochaForm.beizhu}}
              </span>
            </el-form-item>
            <div style="clear:both"></div>
            <el-form-item label="办理结果">
              <span class="selectioncontent">
                <template v-if="kaochaForm.stateExamination===2">考察完成通过提请审议</template>
                <template v-else-if="kaochaForm.stateExamination===3">考察未通过</template>
              </span>
            </el-form-item>
          </el-form>
              <notice :noticePersonId="personId" step="4"></notice>
    </section>
  </div>
</template>

<script>
import notice from '../common/Notice'
export default {
  props: ['personId'],
  watch: {
    personId: {
      handler (val, oldVal) {
        console.log('person:')
        console.log(val)
        if (val && val !== '') {
          this.getKaochaData(val)
          this.getftsb(val)
        }
      },
      immediate: true
    }
  },
  components: {
    notice
  },
  name: 'kaocha-details',
  data () {
    return {
      tableHeight: 100,
      params: {},
      kaochaForm: {
        name: '',
        date: '',
        date2: '',
        num: 0,
        num2: 0,
        num3: 0,
        num4: 0,
        beizhu: '',
        zyqk: '',
        rqbg: '',
        hcr: '',
        problem: '',
        hasproblem: ''
      },
      ftsb: [
        {
          ftsb1: '',
          ftsb2: '',
          ftsb3: '',
          ftsb4: ''
        }
      ],
      files: [],
      fileList: [],
      selectData: {
        hjData: [
        ],
        szData: [
        ],
        cnData: [],
        yyData: []
      },
      loading: false,
      pageloading: false
    }
  },
  methods: {
    exportdoc () {
      window.open(this.$http.defaults.baseURL + this.$http.defaults.selectionAPI + 'api/selection/document/exportPersonRegisterDoc?personId=' + this.personId)
    },
    exportdoc2 () {
      let url = this.$http.defaults.selectionAPI + 'api/selection/document/exportCygbda?personId=' + this.personId
      // console.log(url)
      this.$http.get(url).then(res => {
        if (res.data.success === true) {
          this.download(res.data.result)
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
      // window.open(this.$http.defaults.baseURL + this.$http.defaults.selectionAPI + 'api/selection/document/exportDhjlb?batchId=' + id)
    },
    download (fileid) {
      var downloadElement = document.createElement('a')
      downloadElement.href = this.$http.defaults.baseURL + this.$http.defaults.selectionAPI + 'api/gen/file/download?id=' + fileid
      document.body.appendChild(downloadElement)
      downloadElement.click() // 点击下载
      document.body.removeChild(downloadElement) // 下载完成移除元素
    },
    inRoles (str) {
      console.log(str)
      let arr = JSON.parse(localStorage.getItem('Roles'))
      // arr = 'aaabbROLE_admin'
      if (arr.indexOf(str) === -1) {
        return false
      } else {
        return true
      }
    },
    getKaochaData (id) {
      console.log('获取考察id:' + id)
      this.pageloading = true
      let url = this.$http.defaults.selectionAPI + 'api/selection/examination/getInfo'
      this.$http.get(url, {
        params: {
          personId: id
        }
      }).then(res => {
        this.pageloading = false
        console.log('kaochad2 data:', res)
        if (res.data.success === true) {
          let rs = res.data.result
          let arr = {}
          arr.name = rs.teamMembers
          arr.examinationRange = JSON.parse(rs.examinationRange)
          arr.date = rs.examinationDate
          arr.finishTime = rs.finishTime
          arr.date2 = rs.verifyTime
          arr.num = rs.noTotal
          arr.num2 = rs.noDisagreement
          arr.num3 = rs.noAgreed
          arr.num4 = rs.noAbstentions
          arr.beizhu = rs.remarks
          arr.stateExamination = rs.stateExamination
          arr.ftsb = this.ftsb
          arr.zyqk = rs.importantSituation
          arr.rqbg = rs.report
          arr.hcr = rs.verifyUserName
          arr.problem = rs.hasProblem
          arr.hasproblem = rs.problemComment
          arr.files = rs.files
          this.kaochaForm = arr
        }
      })
    },
    getftsb (personid) {
      if (personid) {
        this.loading = true
        let url = this.$http.defaults.selectionAPI + 'api/selection/necessary/getPersonStepInfo'
        this.$http.post(url, {
          personId: personid
        }).then(response => {
          console.log('ftsb:', response)
          if (response.data.success) {
            let result1 = ''
            let result2 = ''
            let result3 = ''
            let result4 = ''
            if (response.data.result.stateCadreArchives === -1 || response.data.result.resultCadreArchives === '' || !response.data.result.resultSolicitingOpinions) {
              result1 = '无'
            } else {
              result1 = response.data.result.resultCadreArchives
            }
            if (response.data.result.statePersonalMatters === -1 || response.data.result.resultPersonalMatters === '' || !response.data.result.resultSolicitingOpinions) {
              result2 = '无'
            } else {
              result2 = response.data.result.resultPersonalMatters
            }
            if (response.data.result.stateSolicitingOpinions === -1 || response.data.result.resultSolicitingOpinions === '' || !response.data.result.resultSolicitingOpinions) {
              result3 = '无'
            } else {
              result3 = response.data.result.resultSolicitingOpinions
            }
            if (response.data.result.stateClueReporting === -1 || response.data.result.resultClueReporting === '' || !response.data.result.resultSolicitingOpinions) {
              result4 = '无'
            } else {
              result4 = response.data.result.resultClueReporting
            }
            this.ftsb[0].ftsb1 = result1
            this.ftsb[0].ftsb2 = result2
            this.ftsb[0].ftsb3 = result3
            this.ftsb[0].ftsb4 = result4
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
          this.loading = false
        }).catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
          this.loading = false
        })
      }
    }
  }
}
</script>

<style>
.kaocha-details .el-table--border td, .el-table--border th, .el-table__body-wrapper .el-table--border.is-scrolling-left~.el-table__fixed{
  border-bottom:1px solid #95B8E7;
}
.kaocha-details .el-table td, .el-table th.is-leaf{
  border-right:1px solid #95B8E7;
}
.kaocha-details .wboxnoborder .el-table{
  border: #95B8E7 solid 1px;
}
.kaocha-details .wboxnoborder .el-table th{
  font-weight: normal;
  background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  text-align: center;
  border-right: #95B8E7 solid 1px;
  border-bottom: #95B8E7 solid 1px;
  min-height: 30px;
  line-height:30px;
}
.kaocha-details .wboxnoborder .el-table td, .el-table th{
  padding:0;
  font-size:var(--size14) !important;
  line-height: 20px;
  font-family: '宋体';
  text-align: center;
}
.kaocha-details .el-table__row{
  height: 50px;
}
.kaocha-details .el-form-item__content{
  font-weight: bolder;
}
</style>
<style scoped>
.kaocha-details {
  width: 100%;
}
.sel-tit {
  padding: 0 15px;
  box-sizing: border-box;
  float: left;
  text-align: right;
}
.sel-con {
  width: 100%;
  padding: 0 15px;
  box-sizing: border-box;
  float: left;
  border-bottom: 0.5px solid #909399;
  font-size: 14px;
}
.sel-fl {
  float: left;
  font-weight: bolder;
}
.kaocha-details .wboxnoborder {
  padding: 0;
  width: 100%;
  background-color: #fff;
  margin: 0 10px;
  overflow: hidden;
}
</style>
